@include('admin._include.header')
<body class="auth-user">
<div class="layui-fluid">
    <div class="layui-row larryms-panel auth-user-add">
        <form class="layui-form " method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">规格名称</label>
                <div class="layui-input-inline" >
                    <input type="text" name="sku_name"  lay-verify="required" placeholder="请填写规格名称"  value="{{$model->sku_name}}" autocomplete="off" class="layui-input larry-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">规格属性</label>
                    @if(is_array($model->sku_value))
                        @foreach($model->sku_value as $item)
                            <div class="layui-input-block">
                                <button class="layui-btn layui-btn-primary layui-btn-sm" type="button">{{$item}}</button>
                                <input type="hidden" name="sku_value[]" value="{{$item}}">
                                <button  class="layui-btn layui-btn-primary layui-btn-sm del_tag" type="button"><i class="layui-icon"></i></button>
                            </div>
                        @endforeach
                    @endif
                <div class="layui-input-block">
                    <button type="button" id="add_tag" class="layui-btn layui-btn-sm"><i class="layui-icon"></i></button>
                </div>
            </div>

            <div class="layui-form-item" style="text-align: center">
                <input type="hidden" name="id" value="{{$model->id}}">
                <button class="layui-btn" lay-submit lay-filter="ad_add">确定</button>
            </div>
        </form>
    </div>
</div>

<script>
    layui.config({
        base: "/plugin/layuiadmin/" //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'upload','form'], function(){
        var $ = layui.jquery,
        form = layui.form;

        form.on('submit(ad_add)', function(data) {
            var index = layer.load(1);
            $.ajax({
                url:"{{url('sku/edit')}}",
                dateType:'json',
                data:data.field,
                type:'post',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success:function (res) {
                    layer.close(index);
                    layer.msg(res.message);
                    if(res.status == SUCCESS){
                        var iframe = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(iframe); //再执行关闭
                    }
                }
            });

            return false;
        });

        $("#add_tag").on('click',function () {
            var that = $(this);
            var _tag = layer.open({
                title: '添加属性',
                type: 1,
                area: ['300px', '200px'],
                content:"<input type='text' class='layui-input-inline tag_input'  style='padding: 0 10px' placeholder='请填写规格'/>",
                shadeClose: true,
                closeBtn : 2,
                btn: ["确认","取消"],
                btnAlign: 'c',
                yes: function () {
                    that.parent().before(" <div class=\"layui-input-block\">\n" +
                        "                    <button class=\"layui-btn layui-btn-primary layui-btn-sm\" type=\"button\">"+$('.tag_input').val()+"</button>\n" +
                        "                    <input type=\"hidden\" name=\"sku_value[]\"  value="+$('.tag_input').val()+">"+
                        "                    <button class=\"layui-btn layui-btn-primary layui-btn-sm del_tag\"  type=\"button\"><i class=\"layui-icon\"></i></button>\n" +
                        "                </div>");
                    layer.close(_tag)
                    $('.tag_input').val('');

                }
            });
        });


        $(document).on("click",".del_tag",function () {
            var that = $(this);

            layer.confirm('是否确认删除', {
                btn: ['取消','确认'], //按钮
                title:'温馨提示'
            }, function(){
                layer.closeAll();
            }, function(){
                that.parent().remove();
            });

        });

    });
</script>

</body>
@include('admin._include.footer')